﻿@model ITS.Core.ViewModel.Users.UsersModel
@{
    ViewBag.Title = "Users";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using (Html.BeginForm())
{
    @Html.HiddenFor(m => m.UserToDelete)
    <div class="information">
        <div class="header">
            <span>Admin Users</span>
        </div>
        <div class="clear">
        </div>
        <div class="table_detail">
            <table border="0" cellspacing="0" width="100%">
                <tbody>
                    <tr class="title">
                        <td class="user_name left">
                            User Name
                        </td>
                        <td class="role">
                            Role
                        </td>
                        <td class="action">
                            Action
                        </td>
                    </tr>
                    @for (int i = 0; i < Model.Users.Count; i++)
                    {
                        <tr class="@(i % 2 == 0 ? "content" : "content bg_colum")">
                            <td class="user_name left">
                                @Model.Users[i].UserName
                            </td>
                            <td class="role">
                                @if (@Model.Users[i].Roles.Count > 0)
                                {
                                    @Model.Users[i].Roles.First().RoleName
                                }
                            </td>
                            <td class="action">
                                <span>@Html.ActionLink("Edit", "EditUser", "User", new { ID = @Model.Users[i].UserID }, null)</span>
                                <span><a href="#" class="deleteUser" data-id="@Model.Users[i].UserID" data-name="@Model.Users[i].UserName">
                                    Delete</a> </span>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
    </div>
}
<div class="submit_link space_top">
    @Html.ActionLink("Create new user", "createuser")
    <a href="@Url.Action("Index", "Home")"><span>Homepage</span> </a>
</div>
<script type="text/javascript" src="../../Scripts/jquery-1.5.1.min.js"></script>
<script type="text/javascript">
    $(".deleteUser").click(function (e) {
        var recordToDelete = $(this).attr("data-id");
        var recordToDelete2 = $(this).attr("data-name");
        document.getElementById("UserToDelete").value = recordToDelete;
        e.preventDefault();
        if (confirm("Are you sure you want to delete user " + recordToDelete2 + "?")) {
            $(this).parents("form").submit();
        }
    });
</script>
